package com.softserveinc.ita.kaiji.model.player;

import com.softserveinc.ita.kaiji.model.Card;
import com.softserveinc.ita.kaiji.model.DeckImpl;

/**
 * Represents basic real player
 * @author  Ievgen Sukhov
 * @since 16.03.14
 * @version 1.5
 */

public class HumanPlayer extends AbstractPlayer {


    public HumanPlayer() {}

    public HumanPlayer(String name, Integer cardNumber) {
        this.name = name;
        this.deck = new DeckImpl(cardNumber);
        this.canPlay = true;
        statusChanger.switchState(PlayerStatus.TURN_READY);
    }

    @Override
    public Boolean isBot() {
        return false;
    }

    @Override
    public void makeTurn(Card card) {
        logger.info("Making turn for player: "+ this.getName());
        if (statusChanger.getCurrentState()==PlayerStatus.TURN_READY){

            if  (this.deck.pickCard(card)) {
            this.chosenCard = card;
            statusChanger.switchState(PlayerStatus.TURN_FINISHED);
        } else {
            this.chosenCard = null;
            statusChanger.switchState(PlayerStatus.PLAYER_BROKEN);
           throw new IllegalArgumentException("No such card in the deck!");
        }

        } else {
            statusChanger.switchState(PlayerStatus.PLAYER_BROKEN);
            throw new IllegalStateException("Can not make turn, wrong state!");
        }

    }

}
